<?php
import("data.db.DbAbstractTable");

class DbStorageInfo extends DbAbstractTable {
	
	public $className = "data.logic.file.StorageInfo";
	const CLASS_NAME = "data.logic.file.StorageInfo";
	//
	// SQL Table description section
	//
	const TB_TABLENAME	= "pd_storage_info";
	const TB_I			= 'strg';
	
	const TB_NAME		= 'strg_name';
	const TB_CLASS		= 'strg_class';
	const TB_LOGIN		= 'strg_login';
	const TB_PASSWORD	= 'strg_password';
	const TB_CAPACITY	= 'strg_capacity';
	const TB_ACCESSBL	= 'strg_accessable';
	const TB_MUSTREFRESH	= 'strg_mustrefresh';
	
	public static function _get_TABLENAME() {return self::TB_TABLENAME;}
	public static function _get_ID() {return self::TB_I."_id";}
	public static function _get_SUFFIX() {return self::TB_I;}
	//
	//

	// properties
	public $name;
	public $class;
	public $login;
	public $password;
	public $capacity;
	public $accessable;
	public $mustrefresh;
	
	public function __construct($noinit=false) {
		parent::__construct($noinit);
	}
	
	function getName() {
		return $this->name;
	}
	function setName($value) {
		$this->name = $value;
	}
	
	function getStorageClass() {
		return $this->class;
	}
	function setStorageClass($value) {
		$this->class = $value;
	}
	
	function getLogin() {
		return $this->login;
	}
	function setLogin($value) {
		$this->login = $value;
	}
	
	function getPassword() {
		return $this->password;
	}
	function setPassword($value) {
		$this->password = $value;
	}
	
	function getCapacity() {
		return $this->capacity;
	}
	function setCapacity($value) {
		$this->capacity = $value;
	}
	
	function getAccessable() {
		return $this->accessable;
	}
	function setAccessable($value) {
		$this->accessable = $value;
	}
	
	function getMustrefresh() {
		return $this->mustrefresh;
	}
	function setMustrefresh($value) {
		$this->mustrefresh = $value;
	}
	
	// restore
	function fillEntity($arrResult) {
		DbAbstractTable::fillEntity($arrResult);
		$this->setName($arrResult[self::TB_NAME]);
		$this->setStorageClass($arrResult[self::TB_CLASS]);
		$this->setLogin($arrResult[self::TB_LOGIN]);
		$this->setPassword($arrResult[self::TB_PASSWORD]);
		$this->setCapacity($arrResult[self::TB_CAPACITY]);
		$this->setAccessable($arrResult[self::TB_ACCESSBL]);
		$this->setMustrefresh($arrResult[self::TB_MUSTREFRESH]);
	}
	
	//store
	function fillFields() {
		DbAbstractTable::fillFields();
		$this->fildsForStore[self::TB_NAME] = "'".$this->getName()."'";
		$this->fildsForStore[self::TB_CLASS] = "'".$this->getStorageClass()."'";
		$this->fildsForStore[self::TB_LOGIN] = "'".$this->getLogin()."'";
		$this->fildsForStore[self::TB_PASSWORD] = "'".$this->getPassword()."'";
		$this->fildsForStore[self::TB_CAPACITY] = "'".$this->getCapacity()."'";
		$this->fildsForStore[self::TB_ACCESSBL] = "'".$this->getAccessable()."'";
		$this->fildsForStore[self::TB_MUSTREFRESH] = "'".$this->getMustrefresh()."'";
	}
	
	public static function findByName($name) {
		return DbAbstractTable::__selectByCriteria(self::TB_NAME."='".$name."'", self::CLASS_NAME);
	}
	
	public static function findAllHighScore($count) {
		return DbAbstractTable::__selectObjects("SELECT * FROM pd_storage_info order by strg_accessable desc, strg_capacity desc, strg_mustrefresh limit ".$count,
			self::CLASS_NAME);
	}
	
	// same for all classes
	public static function findAll() {return DbAbstractTable::findAll(self::CLASS_NAME);}
    public static function findById($id) {return DbAbstractTable::findById($id, self::CLASS_NAME);}
}
?>